/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */

/*
 * BoneListPanel.java <p/> Created on Jul 28, 2011, 9:00:12 PM
 */
package org.MyTool.AnimationControlTool;

import com.jme3.animation.AnimControl;
import com.jme3.animation.Bone;
import javax.swing.tree.TreeModel;
import org.netbeans.swing.outline.DefaultOutlineModel;
import org.netbeans.swing.outline.OutlineModel;

/**
 *
 * @author hungcuong
 */
public class BoneListPanel extends javax.swing.JPanel {

    private TreeModel treeMdl;
    private AnimControl animControl;

    /**
     * Creates new form BoneListPanel
     */
    public BoneListPanel() {
        initComponents();
    }

    public void updateBoneTable() {
        if (animControl != null) {
            if (animControl.getSkeleton() != null) {
                treeMdl = new BoneTreeModel(animControl.getSkeleton().getRoots()[0]);
            } else {
                return;
            }
        }
        //Create the Outline's model, consisting of the TreeModel and the RowModel,
        //together with two optional values: a boolean for something or other,
        //and the display name for the first column:
        OutlineModel mdl = DefaultOutlineModel.createOutlineModel(
                treeMdl, new BoneRowModel(), true, "Bone");
        //Assign the model to the Outline object:
        outline1.setModel(mdl);

    }

    public void initBonePanel() {
        treeMdl = new BoneTreeModel(new Bone("Null"));
        updateBoneTable();
        //Create the Outline's model, consisting of the TreeModel and the RowModel,
        //together with two optional values: a boolean for something or other,
        //and the display name for the first column:
        OutlineModel mdl = DefaultOutlineModel.createOutlineModel(
                treeMdl, new BoneRowModel(), true, "Bone");


        //By default, the root is shown, while here that isn't necessary:
        outline1.setRootVisible(false);

        //Assign the model to the Outline object:
        outline1.setModel(mdl);

        //Add the Outline object to the JScrollPane:
        scrollBoneView.setViewportView(outline1);

        outline1.setRenderDataProvider(new BoneRenderData());

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrollBoneView = new javax.swing.JScrollPane();
        outline1 = new org.netbeans.swing.outline.Outline();

        scrollBoneView.setViewportView(outline1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 671, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scrollBoneView, javax.swing.GroupLayout.PREFERRED_SIZE, 609, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(52, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 309, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(scrollBoneView, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(36, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.netbeans.swing.outline.Outline outline1;
    private javax.swing.JScrollPane scrollBoneView;
    // End of variables declaration//GEN-END:variables
}
